package com.kzj.mls.recyclerCard.cardView;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kzj.mls.R;
import com.kzj.mls.activity.GBaseActivity;
import com.kzj.mls.beans.ServiceBookBean;
import com.kzj.mls.recyclerCard.basic.CardItemView;
import com.kzj.mls.recyclerCard.card.other.SelectStoreCard;
import com.kzj.mls.widget.dialog.SweetDialogManager;

import cn.pedant.SweetAlert.SweetAlertDialog;
import de.greenrobot.event.EventBus;

/**
 * Created by xyg on 2015/10/26.
 */
public class SelectStoreCardView extends CardItemView<SelectStoreCard> {
    private ServiceBookBean.ServiceAddrEntity serviceAddrEntity;
    private Context context;
    private TextView textView_name;
    private TextView textView_address;
    private TextView textView_distance;
    private ImageView imageView_select;
    private TextView textView_tel;
    private TextView textView_call;

    public SelectStoreCardView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public SelectStoreCardView(Context context) {
        super(context);
        this.context = context;
    }

    public SelectStoreCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public void build(final SelectStoreCard card) {
        super.build(card);
        serviceAddrEntity = card.getServiceAddrEntity();
        textView_name = (TextView) findViewById(R.id.textView_name);
        textView_address = (TextView) findViewById(R.id.textView_address);
        textView_distance = (TextView) findViewById(R.id.textView_distance);
        imageView_select = (ImageView) findViewById(R.id.imageView_select);
        textView_name.setText(serviceAddrEntity.getStore_name());
        textView_address.setText(serviceAddrEntity.getService_address());
        textView_distance.setText(serviceAddrEntity.getRange());
        textView_tel = (TextView) findViewById(R.id.textView_tel);
        textView_call = (TextView) findViewById(R.id.textView_call);
        textView_tel.setText("电话：" + serviceAddrEntity.getTel());
        textView_call.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                SweetDialogManager.getInstance().showDialogByWarmTitleText((GBaseActivity) context,
                        "呼叫" + serviceAddrEntity.getTel(), null, true, true, new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sweetAlertDialog) {
                                sweetAlertDialog.dismiss();
                            }
                        }, new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sweetAlertDialog) {
                                sweetAlertDialog.dismiss();
                                Intent intent6 = new Intent(Intent.ACTION_DIAL,
                                        Uri.parse("tel:" + serviceAddrEntity.getTel()));
                                context.startActivity(intent6);
                            }
                        });
            }
        });
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView_select.setImageResource(R.drawable.icon_correct);
                EventBus.getDefault().post(card.getServiceAddrEntity());
                ((GBaseActivity) context).finish();
            }
        });
    }
}
